﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class ePioneer_ep_pioneer : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        //Page.ClientScript.RegisterStartupScript(GetType(), "s", "<script type='text/javascript'>OpenDialog();</script>");
        HttpCookie cookie = Request.Cookies["Users"];
        if (cookie != null)
        {
            if (cookie["userid"] != "")
                Session["userid"] = cookie["userid"];
            if (cookie["shareID"] != "")
                shareId.Value = cookie["shareID"];
        }
        if (!IsPostBack)
        {
            int typeid = 1;
            if (Request["typeid"] != "" && Request["typeid"] != null)
            {
                typeid = Convert.ToInt32(Request["typeid"]);
                if (typeid == 0)
                {
                    Response.Redirect("ep_service.aspx");
                }
            }
            typeId.Value = typeid.ToString();
            GetQuestionList(typeid);
            GetKnowledgesByTypeid(typeid);
            GetRealList(typeid);
        }
    }

    /// <summary>
    /// 获取常见问题信息
    /// </summary>
    /// <param name="typeid"></param>
    public void GetQuestionList(int typeid)
    {
        StringBuilder sbReturn = new StringBuilder();
        if (typeid > 4)
            typeid = 1;
        string cmsService = System.Configuration.ConfigurationManager.ConnectionStrings["CMSService"].ToString();
        cmsService += "ep_question.ashx?action=GetQuestionListForPioneer&typeid=" + typeid;
        var qlist = UrlGet.GetObject<List<ePioneer_Question>>(cmsService).Where(a => a.IsCheck == 1).OrderByDescending(p => p.Count).Take(4);
        foreach (var n in qlist)
        {
            sbReturn.AppendLine("<div class='black' title='" + n.Title.ToString() + "'>" + n.Count + " <a href='javascript:void(0)' onclick='AddCount(" + n.ID + ")'>" + n.Title.ToString() + "</a></div>");
        }
        question_list.InnerHtml = sbReturn.ToString();
    }

    /// <summary>
    /// 获取首页——你知道吗
    /// </summary>
    /// <param name="typeid"></param>
    public void GetKnowledgesByTypeid(int typeid)
    {
        StringBuilder sbReturn = new StringBuilder();
        if (typeid > 4)
            typeid = 1;
        string cmsService = System.Configuration.ConfigurationManager.ConnectionStrings["CMSService"].ToString();
        cmsService += "ep_question.ashx?action=GetKnowledgesByTypeid&typeid=" + typeid;
        var kList = UrlGet.GetObject<List<ePioneer_Knowledges>>(cmsService);

        foreach (var t in kList)
        {
            if (t == kList[0])
                sbReturn.AppendLine("<div class='clk_cnt1' style='display:block;' title='" + t.Knowledges + "'>" + t.Knowledges + "</div>");
            else
                sbReturn.AppendLine("<div class='clk_cnt1' title='" + t.Knowledges + "'>" + t.Knowledges + "</div>");
        }

        klist.InnerHtml = sbReturn.ToString();
    }

    /// <summary>
    /// 加载最高战法
    /// </summary>
    /// <param name="typeid"></param>
    public void GetRealList(int typeid)
    {
        string cmsService = System.Configuration.ConfigurationManager.ConnectionStrings["CMSService"].ToString();
        StringBuilder sbReturn = new StringBuilder();
        int classes = 8;
        if (typeid == 2)
            classes = 32;
        if (typeid == 3)
            classes = 1048576;
        if (typeid == 4)
            classes = 16;
        if (typeid == 10)
            classes = 256;
        cmsService += "ep_real.ashx?action=GetRealListForPioneer&typeid=" + classes;
        int iCount = 0;
        List<ePioneer_Real> rpioneerlist = UrlGet.GetObject<List<ePioneer_Real>>(cmsService).OrderByDescending(p => p.Average).ToList();
        foreach (var n in rpioneerlist)
        {
            if (iCount >= 4)
            {
                break;
            }
            string r_brief = "";
            if (n.Brief != "" && n.Brief.Length > 20)
            {
                r_brief = n.Brief.Substring(0, 20) + "...";
            }
            else
                r_brief = n.Brief;
            //平均分
            var Average = n.Average;
            //评论条数
            int iRCcount = int.Parse(n.Count);
            sbReturn.AppendFormat("	<div class=\"litem\"><img src=\"{0}\" width=\"36\" height=\"36\" class=\"limg\"/>\r\n", n.Img);
            sbReturn.AppendLine(" <div class=\"lbox1\"><strong><a href='ep_real.aspx?id=" + n.ID + "'\">" + n.Name + "</a></strong><div class=\"linfo\">" + r_brief + "</div></div><div class=\"lbox2\"><div class=\"zf_score" + Math.Round(Convert.ToDecimal(Average)) + "\"> </div> <a href=\"ep_comment.aspx?realId=" + n.ID + "\">基于" + iRCcount + "条评论</a></div>");
            sbReturn.AppendLine("</div>");
            iCount++;
        }
        real_list.InnerHtml = sbReturn.ToString();
    }
}